<!--布局begin-->
<layout name="public/layout" replace="{__CONTENT__}"/>
<!--布局end-->
<div class="middle-box text-center loginscreen  animated fadeInDown" ms-keyup="$enterLogin()">
    <div>
        <div>
            <h1 class="logo-name"><span class="text-danger">M</span></h1>
        </div>
        <h3>欢迎使用 <span class="text-success">Migrate</span></h3>
        <div>
            <div class="form-group">
                <input id="id_account" type="text" class="form-control" placeholder="用户名" required=""
                       ms-duplex="account">
            </div>
            <div class="form-group">
                <input type="password" class="form-control" placeholder="密码" required="" ms-duplex="password">
            </div>
            <button type="button" class="btn btn-primary block full-width m-b" ms-click="$login">登 录</button>
        </div>
    </div>
</div>
<script type="text/javascript">

    var login = avalon.define({
        $id: 'avalon_controller',
        $init: function () {
            $('#id_account').focus();
        },
        account: '',
        password: '',
        $login: function () {
            $.post('/migrate/user/login', {
                account: login.account,
                password: login.password
            }, function (r) {
                if (r.status == 'migrate/user/login/3') {
                    //存入cookie
                    jCommon.cookieAdd('token', r.info.token, 24 * 3600);
                    //跳转
                    window.location.href = '{:url("tables/index")}';
                } else {
                    layer.msg(r.message, function () {
                    });
                }
            });
        },
        $enterLogin: function (event) {
            if (event.keyCode === '13' || event.key.toLowerCase() === 'enter') {
                login.$login();
            }
        }
    });

    avalon.ready(function () {
        login.$init();
    });
</script>